package com.order.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class NutritionDBUtil {
	public static Connection con;
	public static List<String[]> getAllNurition(){	
		List<String[]> list=new ArrayList<String[]>();
		try{
			con=DBConnection.getConnect();
			Statement st=con.createStatement();
			String sql="select * from vegenutrition";
			ResultSet rs=st.executeQuery(sql);
			while(rs.next()){
				String users[]=new String[2];
				for(int i=0;i<users.length;i++)
				{
					users[i]=rs.getString(i+1);
					
				}
				list.add(users);
			}
			rs.close();
			st.close();
			con.close();
			
		}catch(Exception e){
			e.printStackTrace();
		}
		return list;
  }
public static String[] getNutritionByid(String id){
		String info[]=new String[2];
		try{
			con=DBConnection.getConnect();
			Statement st=con.createStatement();
			String sql="select * from vegenutrition where nutri_id='"+id+"'";
			ResultSet rs=st.executeQuery(sql);
			if(rs.next()){
				
					info[0]=rs.getString(1);
					info[1]=rs.getString(2);
			}
			rs.close();
			st.close();
			con.close();
		}catch(Exception e){
			e.printStackTrace();
		}
		return info;
  }
public static String getMaxId(){
 	String max=null;
 	String sql=null;
 	try{
	//Class.forName(driver);
    con=DBConnection.getConnect();
		Statement st=con.createStatement();
		sql="select max(nutri_id) from vegenutrition";
		 System.out.println(sql);
	   ResultSet rs=st.executeQuery(sql);
	   if(rs.next()){
   max=rs.getString(1);
	}
	rs.close();
    st.close();
    con.close();
 	}catch(Exception e){
		e.printStackTrace();
	}
	return max;
}
public static boolean isHasFK(String id){
	String sql=null;
	try{
		//Class.forName(driver);
	    con=DBConnection.getConnect();
			Statement st=con.createStatement();
			sql="select nutri_id from nutrition_curve";
			 System.out.println(sql);
		   ResultSet rs=st.executeQuery(sql);
		   while(rs.next()){
	              if(rs.getString(1).equals(id))return false;
		}
		rs.close();
	    st.close();
	    con.close();
	 	}catch(Exception e){
			e.printStackTrace();
		}
	return true;
}
}
